home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / Common / ZUnitTest.h < prev    next >
Text File  |  1997-08-07  |  3KB  |  122 lines

  1. /*
  2.  *  File:       ZUnitTest.h
  3.  *  Summary:       Singleton that keeps pointers to test functions.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     6/20/97    JDJ        Renamed TUnitTest TUnitTests.
  12.  *         <1>     6/29/96    JDJ        Created
  13.  */
  14.  
  15. #pragma once
  16.  
  17. #include <Types.h>
  18.  
  19. #include <String>
  20.  
  21. #include <ZConstants.h>
  22. #include <ZTypes.h>
  23.  
  24.  
  25. #if DEBUG
  26.  
  27. //-----------------------------------
  28. //    Forward References
  29. //
  30. class ZUnitTestSet;
  31.  
  32.  
  33. //-----------------------------------
  34. //    Types
  35. //
  36. typedef void (*TestProc)();
  37.  
  38.  
  39. // ===================================================================================
  40. //    struct SUnitTest
  41. // ===================================================================================
  42. struct SUnitTest {
  43.     string        name;
  44.     TestProc    test;
  45.     
  46.                 SUnitTest()                                        {name = ""; test = nil;}
  47.         
  48.                 SUnitTest(const string& text)                    {name = text; test = nil;}
  49.     
  50.                 SUnitTest(const string& text, TestProc func)    {name = text; test = func;}
  51.     
  52.     bool        operator==(const SUnitTest& rhs) const            {return name == rhs.name;}
  53.     
  54.     bool        operator<(const SUnitTest& rhs) const            {return name < rhs.name;}
  55. };
  56.  
  57.  
  58. // ===================================================================================
  59. //    class TUnitTests
  60. // ===================================================================================
  61. class TUnitTests {
  62.  
  63. //-----------------------------------
  64. //    Initialization/Destruction
  65. //
  66. public:
  67.                          ~TUnitTests();
  68.     
  69.     static    TUnitTests*    Instance();
  70.  
  71. protected:
  72.                         TUnitTests();
  73.                         
  74. private:
  75.                         TUnitTests(const TUnitTests& rhs);
  76.     
  77.             TUnitTests& operator=(const TUnitTests& rhs);
  78.  
  79. //-----------------------------------
  80. //    API
  81. //
  82. public:
  83.             void        AddTest(const string& name, TestProc test);
  84.                         
  85.             bool        IsTest(const string& name) const;
  86.             
  87.             ulong        GetCount() const;
  88.  
  89.             void        DoTest(const string& name);
  90.             
  91.             void        DoAllTests();
  92.             
  93.             
  94.             void        ResetCursor();
  95.             
  96.             SUnitTest    GetNextTest();
  97.             
  98.             bool        CursorAtEnd() const;
  99.             
  100. //-----------------------------------
  101. //    Member data
  102. //
  103. protected:
  104.     ZUnitTestSet*    mTests;
  105. };
  106.  
  107.  
  108. // ===================================================================================
  109. //    class TUnitTestRegistrar
  110. //        You can declare a static object of this type in your file to automatically
  111. //        register your test.
  112. // ===================================================================================
  113. class TUnitTestRegistrar {
  114.  
  115. public:
  116.                          ~TUnitTestRegistrar();
  117.     
  118.                         TUnitTestRegistrar(const string& name, TestProc test);
  119. };
  120.  
  121.  
  122. #endif    // DEBUG